package com.ttms.service.impl;
import com.ttms.dao.ScheduleDao;
import com.ttms.dao.impl.ScheduleDaoImpl;
import com.ttms.pojo.Page;
import com.ttms.pojo.Play;
import com.ttms.pojo.Schedule;
import com.ttms.service.ScheduleService;
import java.util.List;

public class ScheduleServiceImpl implements ScheduleService {
    private ScheduleDao scheduleDao = new ScheduleDaoImpl();
    @Override
    public void addSchedule(Schedule schedule) {
        scheduleDao.addSchedule(schedule);
    }

    @Override
    public void deleteScheduleById(Integer id) {
        scheduleDao.deleteScheduleById(id);
    }

    @Override
    public void updateSchedule(Schedule schedule) {
        scheduleDao.updateSchedule(schedule);
    }

    @Override
    public Schedule queryScheduleById(Integer id) {
        return scheduleDao.queryScheduleById(id);
    }

    @Override
    public List<Schedule> querySchedules() {
        return scheduleDao.querySchedules();
    }

    @Override
    public Page<Schedule> page(int pageNo, int pageSize) {
        Page<Schedule> page = new Page<Schedule>();
        page.setPageSize(pageSize);
        Integer pageTotalCount = scheduleDao.queryForPageTotalCount();
        page.setPageTotalCount(pageTotalCount);
        Integer pageTotal = pageTotalCount / pageSize;
        if (pageTotalCount % pageSize > 0) {
            pageTotal += 1;
        }
        page.setPageTotal(pageTotal);
        page.setPageNo(pageNo);
        int begin = (page.getPageNo() - 1) * pageSize;
        List<Schedule> items = scheduleDao.querySchedules();
        page.setItems(items);
        return page;
    }

    @Override
    public Page<Schedule> queryScheduleByPlayId(int pageNo, int pageSize, int play_id) {
        Page<Schedule> page = new Page<Schedule>();
        page.setPageSize(pageSize);
        Integer pageTotalCount = scheduleDao.queryScheduleCountByPlayId(play_id);
        page.setPageTotalCount(pageTotalCount);
        Integer pageTotal = pageTotalCount / pageSize;
        if (pageTotalCount % pageSize > 0) {
            pageTotal += 1;
        }
        page.setPageTotal(pageTotal);
        page.setPageNo(pageNo);
        int begin = (page.getPageNo() - 1) * pageSize;
        List<Schedule> items = scheduleDao.queryScheduleByPlayId(begin, pageSize, play_id);
        page.setItems(items);
        return page;
    }
}
